﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JsEditor
{
    public partial class JsVar50 : UserControl
    {
        [Description("选取事件"), Category("自定义事件")]
        public event EventHandler OnValueChanged;
        
        private bool innerEventActive;

        public JsVar50()
        {
            InitializeComponent();
        }

        public bool Checked
        {
            set { innerEventActive = false; checkBox1.Checked = value; innerEventActive = true; }
            get { return checkBox1.Checked; }
        }

        public string CheckBoxName
        {
            set { checkBox1.Text = value; }
            get { return checkBox1.Text; }
        }

        public bool ReadOnly
        {
            set { numericUpDown1.Enabled = !value; }
            get { return !numericUpDown1.Enabled; }
        }

        public int Value
        {
            set { innerEventActive = false; numericUpDown1.Value = value; innerEventActive = true; }
            get { return Decimal.ToUInt16(numericUpDown1.Value); }
        }

        public int MinValue
        {
            set { innerEventActive = false; numericUpDown1.Minimum = value; innerEventActive = true; }
            get { return Decimal.ToInt32(numericUpDown1.Minimum); }
        }

        public int MaxValue
        {
            set { innerEventActive = false; numericUpDown1.Maximum = value; innerEventActive = true; }
            get { return Decimal.ToInt32(numericUpDown1.Maximum); }
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            if (!innerEventActive) return;
            if (OnValueChanged != null)
                OnValueChanged(this, e);
        }
    }
}
